<script type="text/javascript">

 $(document).ready(function() {
  $('#loading').hide();
  $("#attribute_id_group").change(function(){

          var id_group = $('select#attribute_id_group option:selected').val();

          if(id_group == '')
          {
            $('.new').remove();
            return;
          }

    $.ajax({
      type: "POST",
      url: "<?php echo $basePath; ?>/<?php echo $adminAreaToken; ?>/ajax-get-group-attributes-html",
      data: ({id_group : id_group}),
      success: function(data) {
         $('.new').remove();
         $(data).insertAfter('.attribute');
      },
      error: function(data) {
        console.log(data);
      }
    });
  });

  $('')
      $('#loading')
      .ajaxStart(function() {
      $(this).show();
      }).ajaxStop(function() {
      $(this).hide();
      });
 });

</script>

<div class="subcolumns">
  <div class="c75l">

    <h1 id="page_head">Add Item</h1>

    <ul id="node-branch" role="navigation">
    <li><a href="<?php echo $basePath; ?>/<?php echo $adminAreaToken; ?>/list/index/id_list/0">Root</a>/</li>
    <?php foreach( $this->list_branch_result as $branch): ?>
        <li><a href="<?php echo $basePath; ?>/<?php echo $adminAreaToken; ?>/list/index/id_list/<?php  echo $branch['id_list']; ?>"><?php  echo $escape->escapeHtml($branch['title']); ?></a>/</li>
    <?php endforeach; ?>
    </ul>

    <div class="separation">&nbsp;</div>

    <?php if(count($this->error) > 0): ?>
    <div id="error" aria-live="rude">
        <h2>Error:</h2>
        <?php foreach($this->error as $error): ?>
            <h3><?php echo $escape->escapeHtml($error); ?></h3>
        <?php endforeach; ?>
    </div>
    <?php endif; ?>

    <form name="setup" id="setup" method="post" action="<?php echo $basePath; ?>/<?php echo $adminAreaToken; ?>/item-add-new/add" accept-charset="utf-8">

    <input type="hidden" name="id_list" value="<?php echo $this->id_list; ?>" />

    <ul class="ul-form">
        <li class="item_label"><h2><label for="item_name" id="agn">Item title:</label></h2></li>
        <li class="item_content">
                <input aria-required="true"
                       aria-labelledby="agn"
                       name="item_name"
                       id="item_name"
                       tabindex="1"
                       type="text"
                       size="40"
                       maxlength="255"
                       value="<?php echo $escape->escapeHtmlAttr($this->item_name); ?>" />
        </li>

        <li class="item_label"><h2><label for="item_id_status" id="is">Item status:</label></h2></li>
        <li class="item_content">
                    <select name="item_id_status" id="item_id_status" size="1">
                    <option value="100"<?php if($this->item_id_status==100): ?> selected="selected" class="selected"<?php endif; ?>>inactive&nbsp;&nbsp;</option>
                    <option value="200"<?php if($this->item_id_status==200): ?> selected="selected" class="selected"<?php endif; ?>>active&nbsp;&nbsp;</option>
                    </select>
        </li>

        <li class="item_label"><h2><label for="item_lang" id="clang">Item language:</label></h2></li>
        <li class="item_content">
        <select name="item_lang" id="item_lang" size="1" lang="en" tabindex="4">
                <?php foreach($this->languages as $val):  ?>
    <option value="<?php echo $escape->escapeHtmlAttr($val['lang']); ?>"<?php if($this->item_lang==$val['lang']): ?> selected="selected" class="selected"<?php endif; ?>><?php echo $escape->escapeHtml($val['description']); ?></option>
    <?php endforeach; ?>
    </select>
        </li>

        <li class="item_label"><h2><label for="item_description" id="agd">Item description:</label></h2></li>
        <li class="item_content">
                <textarea name="item_description"
                          id="item_description"
                          aria-labelledby="agd"
                          tabindex="5"
                          cols="50"
                          rows="5"><?php echo $escape->escapeHtml($this->item_description); ?></textarea>
        </li>

    </ul>

    <ul class="ul-form attribute" title="select additional attributes from a group">
        <li class="item_label"><h2><label for="attribute_group" id="agroup"><strong>Select attribute group (optional):</strong></label></h2></li>
        <li class="item_content loading">
    <select name="attribute_id_group" id="attribute_id_group" size="1" lang="en" tabindex="6">
      <option value="">None</option>
      <?php foreach($this->attribute_groups as $val):  ?>
      <option value="<?php echo $escape->escapeHtmlAttr($val['id_group']); ?>"<?php if(strcmp($this->attribute_id_group, $val['id_group'])==0): ?> selected="selected" class="selected"<?php endif; ?>><?php echo $escape->escapeHtml($val['title']); ?></option>
      <?php endforeach; ?>
      </select>

    <img id="loading" src="<?php echo $basePath; ?>/admin_media/images/loading-red.gif" alt="loading additional attributes...please wait" />
        </li>
    </ul>

    <?php /**** error on submit. load additional attribute fields with content ****/ ?>
    <?php if(isset($additionalAttributes)): ?>

    <h2 class="attribute_additional_head">Additional list attributes</h2>
      <?php echo $this->partial('layout/_additional_attributes.phtml', 
                                $additionalAttributes); ?>
    <?php endif; ?>

    <ul class="ul-form" title="additional list attributes">
        <li class="item_label"><h2><label for="submit" id="sub">Add new Item or cancel:</label></h2></li>
        <li class="item_content">
            <input role="button"
                   aria-labelledby="sub"
                   type="submit"
                   name="add"
                   id="submit"
                   value="Submit" />

            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

            <input role="button"
                   aria-labelledby="sub"
                   type="submit"
                   name="cancel"
                   id="cancel"
                   value="Cancel" />
        </li>
    </ul>

    </form>


  </div>
  <div class="c25r right_navigation">
      <?php $partialData['basePath'] = $basePath; $partialData['adminAreaToken'] = $adminAreaToken; ?>
      
      <?php echo $this->partial('layout/_list_navigation.phtml', 
                                $partialData); ?>
  </div>
</div>


